// pages/gerenxinxi/gerenxinxi.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag:false,
    openid:'',
    adminname:'',
    name:'',
    sex:0,
    phone:'',
    email:'',
    qq:'',
    address:'',
    user:{
      adminname:'',
      name:'',
      sex:0,
      phone:'',
      email:'',
      qq:'',
      address:''
    },
    gender:'男'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      user:JSON.parse(options.a)
    })
    if(this.data.user.sex==0){
      this.setData({
        gender:'男'
      })
    }else{
      this.setData({
        gender:'女'
      })
    }
    this.setData({
      openid:wx.getStorageSync('openid')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  xiugai:function(){
    this.setData({
      flag:true
    })
  },
  submitForm:function(e){
    console.log(e.detail.value)
    this.setData({
       openid:this.data.openid,
       name:e.detail.value.name,
       sex:e.detail.value.sex,
       phone:e.detail.value.phone,
       email:e.detail.value.email,
       qq:e.detail.value.qq,
       address:e.detail.value.address
    })
    // console.log(this.data.user);
    wx.request({
      url: 'http://localhost:80/UserQuery/updata',
      method:"POST",
      data:{
       openid:this.data.openid,
       name:this.data.name,
       sex:this.data.sex,
       phone:this.data.phone,
       email:this.data.email,
       qq:this.data.qq,
       address:this.data.address
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
    },
    success:res=>{
       this.setData({
      flag:false
    })
    wx.showToast({
      title: '成功',
      icon: 'success',
      duration: 2000//持续的时间
    })
    }
    })
    
  },
  quxiao:function(){
    this.setData({
      flag:false
    })
    wx.showToast({
      title: '失败',
      icon: 'error',
      duration: 2000//持续的时间
    })
  }
})